package com.foxire.method1reference;

import com.foxire.method1reference.Student;

import java.util.Arrays;

public class Demo1 {
    public static void main(String[] args) {
        // 静态方法引用
        test();
    }

    public static void test(){
        Student[] students = new Student[6];
        students[0] = new Student("张三", 18, 180, "男");
        students[1] = new Student("李四", 19, 175, "男");
        students[2] = new Student("王五", 20, 165, "男");
        students[3] = new Student("赵六", 21, 170, "男");
        students[4] = new Student("孙七", 22, 165, "男");
        students[5] = new Student("周八", 23, 180, "男");

//        Arrays.sort(students,(o1, o2) -> o1.getAge() - o2.getAge());
//
//        Arrays.sort(students,(o1, o2) -> Student.compareByAge(o1, o2));
        // 前提: -> 前后参数的形式一致,才可以使用静态方法引用
        Arrays.sort(students,Student::compareByAge); // 静态方法
        // 遍历数组中的对象并输出
        for (int i = 0; i < students.length; i++) {
            System.out.println(students[i]);
        }
    }
}
